package cqrtplm.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hustcad.plm.basic.event.classification.TyplmCutOrCopyClassificationPostEvent;
import com.hustcad.plm.basic.util.TyplmLoggerUtil;
import com.hustcad.plm.pdm.classification.mapper.TyplmClassificationMapper;
import com.hustcad.plm.pdm.classification.model.constant.TyplmClassificationErrorCodeEnum;
import com.hustcad.plm.pdm.classification.model.dto.TyplmClassificationEntityDTO;
import com.hustcad.plm.pdm.classification.model.entity.TyplmClassificationExtendDO;
import com.hustcad.plm.pdm.classification.service.TyplmClassificationExtendService;
import com.hustcad.plm.pdm.classification.service.TyplmClassificationRootService;
import com.hustcad.plm.pdm.classification.service.impl.TyplmClassificationServiceImpl;
import com.hustcad.plm.pdm.constraint.model.vo.TyplmConstraintCreateVO;
import com.hustcad.plm.pdm.constraint.model.vo.TyplmConstraintEditVO;
import com.hustcad.plm.pdm.constraint.model.vo.TyplmConstraintRuleDefVO;
import com.hustcad.plm.pdm.constraint.service.TyplmConstraintService;
import com.hustcad.plm.pdm.enumeration.model.vo.LocalValueVO;
import com.hustcad.plm.pdm.enumeration.service.TyplmLocalePropertyValueService;
import com.hustcad.plm.pdm.iba.service.TyplmAttributeDefService;
import com.hustcad.plm.pdm.iba.service.TyplmAttributeDefaultValueService;
import com.hustcad.plm.pdm.type.model.dto.TypeAttrDTO;
import com.hustcad.plm.pdm.type.service.TyplmTypeService;
import com.ty.basic.dto.TyAttrDefaultValueDTO;
import com.ty.basic.entity.IdentifierEntity;
import com.ty.basic.entity.attribute.AttributeDefMapDO;
import com.ty.basic.entity.type.ClassificationDO;
import com.ty.basic.service.snow.SnowflakeIdComponent;
import com.ty.basic.util.TySpringBeanUtil;
import com.ty.basic.vo.TyAttributeDefMapVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.*;

@Service
@Primary
@Slf4j
public class RTTyplmClassificationServiceImpl extends TyplmClassificationServiceImpl {
    @Resource
    private TyplmClassificationMapper typlmClassificationMapper;
    @Resource
    private SnowflakeIdComponent snowflakeIdComponent;
    @Resource
    private TyplmLocalePropertyValueService typlmLocalePropertyValueService;
    @Resource
    @Lazy
    private TyplmTypeService typlmTypeService;
    @Resource
    @Lazy
    private TyplmConstraintService typlmConstraintService;
    @Resource
    private TyplmAttributeDefaultValueService typlmAttributeDefaultValueService;
    @Resource
    private TyplmClassificationRootService typlmClassificationRootService;
    @Resource
    private TyplmAttributeDefService typlmAttributeDefService;
    @Resource
    @Lazy
    private TyplmClassificationExtendService typlmClassificationExtendService;

    @Transactional(rollbackFor = Exception.class)
    public TyplmClassificationEntityDTO copyToParse(IdentifierEntity currEntity, IdentifierEntity toEntity) {
        List<TyplmClassificationEntityDTO> rootList = this.typlmClassificationRootService.queryClassificationRootByLanguage();
        ClassificationDO currentEntityInfo;
        ClassificationDO currentEntityInfoTemp = new ClassificationDO();
        TyplmClassificationEntityDTO toEntityInfo;
        if (!"ty.inteplm.type.CTyClassification".equals(currEntity.getOtype())) {
            throw TyplmClassificationErrorCodeEnum.CLASSIFICATION_MOVE_ROOT_ERROR.getException();
        } else {
            currentEntityInfo = this.getClassificationByOID(currEntity.getOid());
            BeanUtil.copyProperties(currentEntityInfo, currentEntityInfoTemp);
            String rootID = "";
            String pnodeID;
            if ("ty.inteplm.type.CTyClassificationRoot".equals(toEntity.getOtype())) {
                Optional<TyplmClassificationEntityDTO> data = rootList.stream().filter((item) -> item.getId().equals(toEntity.getOid().toString())).findFirst();
                if (data.isPresent()) {
                    toEntityInfo = data.get();
                    rootID = toEntityInfo.getId();
                }

                pnodeID = "0";
            } else {
                toEntityInfo = this.queryClassificationDTOByOID(currEntity.getOid());
                rootID = toEntityInfo.getRootid();
                pnodeID = toEntity.getOid().toString();
                List<BigInteger> parentList = this.queryAllParentIdByOid(toEntity.getOid(), false);
                TyplmLoggerUtil.debug(log, () -> "复制粘贴分类信息的parentList为==>【{}】", () -> new Object[]{JSONObject.toJSONString(parentList)});
                if (CollUtil.isNotEmpty(parentList) && parentList.stream().anyMatch((item) -> item.compareTo(currEntity.getOid()) == 0) || currEntity.getOid().compareTo(toEntity.getOid()) == 0) {
                    throw TyplmClassificationErrorCodeEnum.CLASSIFICATION_MOVE_PARSE_ERROR.getException();
                }
            }

            if ((new BigInteger(rootID)).compareTo(currentEntityInfo.getClassficationrootoid()) != 0) {
                throw TyplmClassificationErrorCodeEnum.CLASSIFICATION_MOVE_ROOT_OTHER_ERROR.getException();
            } else {
                currentEntityInfo.setParentnodeoid(new BigInteger(pnodeID));
                TyplmClassificationEntityDTO result = this.copyClassData(currEntity, currentEntityInfo);
                TyplmCutOrCopyClassificationPostEvent typlmCopyClassificationPostEvent = new TyplmCutOrCopyClassificationPostEvent(this, currEntity, currentEntityInfo.getIdentifierRef(), false);
                TySpringBeanUtil.getApplicationContext().publishEvent(typlmCopyClassificationPostEvent);
                HashMap<AttributeDefMapDO, AttributeDefMapDO> attrMap = new HashMap<>();
                this.copyClassIba(currEntity, currentEntityInfo, attrMap);
                this.copyChildClassInfo(currentEntityInfoTemp, currentEntityInfo, attrMap);
                return this.queryClassificationDTOByOID(new BigInteger(result.getId()));
            }
        }
    }

    private TyplmClassificationEntityDTO copyClassData(IdentifierEntity oldEntity, ClassificationDO currentInfo) {
        TyplmLoggerUtil.debug(log, () -> "复制分类信息的入参oldEntity为==>【{}】,currentInfo为==>【{}】", () -> new Object[]{JSONObject.toJSONString(oldEntity), JSONObject.toJSONString(currentInfo)});
        TyplmClassificationEntityDTO oldClassEntity = this.queryClassificationDTOByOID(oldEntity.getOid());
        BigInteger oid = this.snowflakeIdComponent.getInstance().nextId();
        currentInfo.setOid(oid);
        /*
          创建新的分类内部名称
          currentInfo.setName(oldClassEntity.getInternalName() + "_"+oid.toString());
         */
        currentInfo.setName(oldClassEntity.getInternalName() + "_"+oid.toString());
        TyplmLoggerUtil.debug(log, () -> "复制分类信息的currentInfo为==>【{}】", () -> new Object[]{JSONObject.toJSONString(currentInfo)});
        this.typlmClassificationMapper.insert(currentInfo);
        IdentifierEntity entity = new IdentifierEntity();
        entity.setOid(oid);
        entity.setOtype(currentInfo.getOtype());
        this.copyClassExtend(oldEntity, currentInfo);
        this.typlmClassificationExtendService.moveClassStep(entity, 9999);
        this.copyClassAttrBase(oldEntity, currentInfo);
        return this.queryClassificationDTOByOID(currentInfo.getOid());
    }

    private void copyClassExtend(IdentifierEntity oldEntity, ClassificationDO currentInfo) {
        TyplmClassificationExtendDO extendInfo = this.typlmClassificationExtendService.getClassExtend(oldEntity.getOid(), oldEntity.getOtype());
        if (Objects.nonNull(extendInfo)) {
            TyplmLoggerUtil.debug(log, () -> "复制扩展信息的extendInfo为==>【{}】", () -> new Object[]{JSONObject.toJSONString(extendInfo)});
            extendInfo.setBaseoid(currentInfo.getOid());
            extendInfo.setBaseotype(currentInfo.getOtype());
            this.typlmClassificationExtendService.saveClassExtend(extendInfo);
        }
    }

    private void copyClassAttrBase(IdentifierEntity oldEntity, ClassificationDO currentInfo) {
        LocalValueVO localValueVO = this.typlmLocalePropertyValueService.queryTypeLocalePropertyValue(oldEntity, "displayName");
        if (Objects.nonNull(localValueVO)) {
            TyplmLoggerUtil.debug(log, () -> "copyClassAttrBase的localValueVO为==>【{}】", () -> new Object[]{JSONObject.toJSONString(localValueVO)});
            localValueVO.setAttributereferenceoid(currentInfo.getOid());
            /*
              修改显示名称
              localValueVO.setValue(localValueVO.getValue()+ "-副本");
             */
            localValueVO.setValue(localValueVO.getValue()+ "-副本");
            this.typlmLocalePropertyValueService.insertTypeLocalePropertyValue(localValueVO);
        }

        LocalValueVO localDisplayValueVO = this.typlmLocalePropertyValueService.queryTypeLocalePropertyValue(oldEntity, "description");
        if (Objects.nonNull(localDisplayValueVO)) {
            TyplmLoggerUtil.debug(log, () -> "copyClassAttrBase的localDisplayValueVO为==>【{}】", () -> new Object[]{JSONObject.toJSONString(localDisplayValueVO)});
            localDisplayValueVO.setAttributereferenceoid(currentInfo.getOid());
            this.typlmLocalePropertyValueService.insertTypeLocalePropertyValue(localDisplayValueVO);
        }

    }

    private void copyClassIba(IdentifierEntity oldEntity, ClassificationDO currentInfo, Map<AttributeDefMapDO, AttributeDefMapDO> attrMap) {
        TyplmLoggerUtil.debug(log, () -> "复制IBA属性的入参oldEntity为==>【{}】,currentInfo为==>【{}】,attrMap==>【{}】", () -> new Object[]{JSONObject.toJSONString(oldEntity), JSONObject.toJSONString(currentInfo), JSONObject.toJSONString(attrMap)});
        IdentifierEntity currEntity = new IdentifierEntity();
        currEntity.setOid(currentInfo.getOid());
        currEntity.setOtype(currentInfo.getOtype());
        List<TyAttributeDefMapVO> attrDefMapList = this.typlmTypeService.queryInheritAttrDef(oldEntity.getOid(), oldEntity.getOtype());
        if (CollUtil.isNotEmpty(attrDefMapList)) {
            TyplmLoggerUtil.debug(log, () -> "复制IBA属性的attrDefMapList为==>【{}】", () -> new Object[]{JSONObject.toJSONString(attrDefMapList)});

            for (TyAttributeDefMapVO item : attrDefMapList) {
                BigInteger newOid = item.getOid();
                boolean isNewAttr = false;
                AttributeDefMapDO attributeDefMapSaveDOBack = new AttributeDefMapDO();
                AttributeDefMapDO attributeDefMapSaveDO = this.typlmAttributeDefService.queryAttributeDefMapByOid(
                        newOid);
                BeanUtil.copyProperties(attributeDefMapSaveDO, attributeDefMapSaveDOBack);
                if (!item.getIsInherit().equalsIgnoreCase("1")) {
                    TypeAttrDTO itemInfo = new TypeAttrDTO();
                    itemInfo.setDescription(item.getDescription());
                    itemInfo.setDisplayName(item.getDisplayName());
                    itemInfo.setName(item.getName());
                    itemInfo.setOid(item.getAttributereferenceoid().toString());
                    itemInfo.setOType(item.getAttributereferenceotype());
                    itemInfo.setTypeOtype(currentInfo.getOtype());
                    itemInfo.setTypeId(currentInfo.getOid().toString());
                    TyplmLoggerUtil.debug(log, () -> "复制IBA属性的itemInfo为==>【{}】",
                                          () -> new Object[]{JSONObject.toJSONString(itemInfo)});
                    newOid = this.typlmTypeService.saveTypeAttributeMap(itemInfo);
                    attributeDefMapSaveDO = this.typlmAttributeDefService.queryAttributeDefMapByOid(newOid);
                    attrMap.put(attributeDefMapSaveDOBack, attributeDefMapSaveDO);
                    isNewAttr = true;
                }

                attributeDefMapSaveDO = this.typlmAttributeDefService.queryAttributeDefMapByOid(newOid);
                this.copyAttrDefValue(item, attributeDefMapSaveDO, oldEntity, currentInfo, attrMap, isNewAttr);
                this.copyConstraint(item, attributeDefMapSaveDO, currentInfo, attrMap, isNewAttr);
            }
        }
    }

    private void copyAttrDefValue(TyAttributeDefMapVO item, AttributeDefMapDO newAttrDef, IdentifierEntity oldEntity, ClassificationDO currentInfo, Map<AttributeDefMapDO, AttributeDefMapDO> attrMap, boolean isNewAttr) {
        TyplmLoggerUtil.debug(log, () -> "复制IBA属性关联的默认值的入参item为==>【{}】,newAttrDef为==>【{}】,oldEntity==>【{}】,currentInfo为==>【{}】,attrMap==>【{}】,isNewAttr==>【{}】", () -> new Object[]{JSONObject.toJSONString(item), JSONObject.toJSONString(newAttrDef), JSONObject.toJSONString(oldEntity), JSONObject.toJSONString(currentInfo), JSONObject.toJSONString(attrMap), isNewAttr});
        List<TyAttrDefaultValueDTO> attributeDefaultValue;
        if (isNewAttr) {
            AttributeDefMapDO attributeDefMapDO = new AttributeDefMapDO();
            attributeDefMapDO.setOid(item.getOid());
            attributeDefMapDO.setAttributereferenceoid(item.getAttributereferenceoid());
            attributeDefMapDO.setAttributereferenceotype(item.getAttributereferenceotype());
            attributeDefaultValue = this.typlmAttributeDefaultValueService.getAttributeDefaultValue(oldEntity.getOid(), oldEntity.getOtype(), attributeDefMapDO);
        } else {
            attributeDefaultValue = this.typlmAttributeDefaultValueService.getAttributeDefaultValue(oldEntity.getOid(), oldEntity.getOtype(), newAttrDef);
        }

        if (!CollectionUtils.isEmpty(attributeDefaultValue)) {
            TyplmLoggerUtil.debug(log, () -> "复制IBA属性关联的默认值的attributeDefaultValue为==>【{}】", () -> new Object[]{JSONObject.toJSONString(attributeDefaultValue)});

            for (TyAttrDefaultValueDTO itemDef : attributeDefaultValue) {
                if (!itemDef.getIsInherit().equalsIgnoreCase("1")) {
                    itemDef.setOid(null);
                    itemDef.setTypeDefOID(currentInfo.getOid());
                    itemDef.setTypeDefOType(currentInfo.getOtype());
                    if (isNewAttr) {
                        itemDef.setAttributeDefOID(newAttrDef.getOid());
                    } else if (attrMap.entrySet().stream().anyMatch(
                            (itemAttr) -> itemAttr.getKey().getOid().compareTo(newAttrDef.getOid()) == 0)) {
                        Optional<Map.Entry<AttributeDefMapDO, AttributeDefMapDO>> resultData = attrMap.entrySet()
                                .stream().filter(
                                        (itemAttr) -> itemAttr.getKey().getOid().compareTo(newAttrDef.getOid()) == 0)
                                .findFirst();
                        if (resultData.isPresent()) {
                            AttributeDefMapDO newAttrDefP = (AttributeDefMapDO) ((Map.Entry<?, ?>) resultData.get()).getValue();
                            itemDef.setAttributeDefOID(newAttrDefP.getOid());
                        }
                    } else {
                        itemDef.setAttributeDefOID(newAttrDef.getOid());
                    }

                    TyplmLoggerUtil.debug(log, () -> "复制IBA属性关联的默认值的itemDef为==>【{}】,newAttrDef为==>【{}】",
                                          () -> new Object[]{JSONObject.toJSONString(itemDef), JSONObject.toJSONString(
                                                  newAttrDef)});
                    this.typlmAttributeDefaultValueService.insertAttributeDefaultValue(itemDef, newAttrDef);
                }
            }
        }
    }

    private void copyConstraint(TyAttributeDefMapVO item, AttributeDefMapDO newAttrDef, ClassificationDO currentInfo, Map<AttributeDefMapDO, AttributeDefMapDO> attrMap, boolean isNewAttr) {
        TyplmLoggerUtil.debug(log, () -> "复制约束的入参item为==>【{}】,newAttrDef为==>【{}】,currentInfo为==>【{}】,attrMap==>【{}】,isNewAttr==>【{}】", () -> new Object[]{JSON.toJSONString(item), JSON.toJSONString(newAttrDef), JSON.toJSONString(currentInfo), JSON.toJSONString(attrMap), isNewAttr});
        List<TyplmConstraintEditVO> constraintEditVOS = this.typlmConstraintService.getConstraint(item);
        List<TyplmConstraintRuleDefVO> constraintRuleDefVOS;
        AttributeDefMapDO currentNew;
        if (isNewAttr) {
            currentNew = new AttributeDefMapDO();
            currentNew.setOid(item.getOid());
            currentNew.setAttributereferenceoid(item.getAttributereferenceoid());
            currentNew.setAttributereferenceotype(item.getAttributereferenceotype());
            constraintRuleDefVOS = this.typlmConstraintService.getConstraintRuleDef(currentNew);
        } else {
            constraintRuleDefVOS = this.typlmConstraintService.getConstraintRuleDef(newAttrDef);
        }

        TyplmLoggerUtil.debug(log, () -> "复制约束的constraintRuleDefVOS为==>【{}】", () -> new Object[]{JSON.toJSONString(constraintRuleDefVOS)});
        if (!CollUtil.isEmpty(constraintEditVOS)) {
            TyplmLoggerUtil.debug(log, () -> "复制约束的constraintEditVOS为==>【{}】", () -> new Object[]{JSON.toJSONString(constraintEditVOS)});
            currentNew = newAttrDef;
            if (attrMap.entrySet().stream().anyMatch((itemAttr) -> itemAttr.getKey().getOid().compareTo(newAttrDef.getOid()) == 0)) {
                Optional<Map.Entry<AttributeDefMapDO, AttributeDefMapDO>> resultData = attrMap.entrySet().stream().filter((itemAttr) -> itemAttr.getKey().getOid().compareTo(newAttrDef.getOid()) == 0).findFirst();
                if (resultData.isPresent()) {
                    currentNew = (AttributeDefMapDO)((Map.Entry<?, ?>)resultData.get()).getValue();
                }
            }

            AttributeDefMapDO finalCurrentNew = currentNew;
            List<TyAttributeDefMapVO> attrDefMapList = this.typlmTypeService.queryInheritAttrDef(currentInfo.getOid(), currentInfo.getOtype());
            if (!CollUtil.isEmpty(attrDefMapList) && attrDefMapList.stream().anyMatch((itemAttr) -> itemAttr.getOid().compareTo(finalCurrentNew.getOid()) == 0)) {
                TyplmLoggerUtil.debug(log, () -> "复制约束的attrDefMapList为==>【{}】", () -> new Object[]{JSON.toJSONString(attrDefMapList)});
                Optional<TyAttributeDefMapVO> resultData = attrDefMapList.stream().filter((itemAttr) -> itemAttr.getOid().compareTo(finalCurrentNew.getOid()) == 0).findFirst();
                TyAttributeDefMapVO tyAttributeDefMapVO = new TyAttributeDefMapVO();
                if (resultData.isPresent()) {
                    tyAttributeDefMapVO = resultData.get();
                }

                List<TyplmConstraintEditVO> currConstraintEditVOS = this.typlmConstraintService.getConstraint(tyAttributeDefMapVO);
                TyplmConstraintCreateVO constraintCreateVO = new TyplmConstraintCreateVO();
                constraintCreateVO.setAttributeDefMapDO(currentNew);
                constraintCreateVO.setTypeOID(currentInfo.getOid().toString());
                constraintCreateVO.setTypeOType(currentInfo.getOtype());
                List<TyplmConstraintRuleDefVO> ruleList = new ArrayList<>();

                // 替换原有的 while(true) 循环块
                for (TyplmConstraintEditVO itemInfo : constraintEditVOS) {
                    // 检查当前约束是否已存在
                    boolean isConstraintExists = CollUtil.isNotEmpty(currConstraintEditVOS) &&
                            currConstraintEditVOS.stream().anyMatch(itemRule ->
                                                                            itemRule.getRuleoid().equals(itemInfo.getRuleoid()));

                    // 如果约束已存在，则跳过
                    if (isConstraintExists) {
                        continue;
                    }

                    // 检查约束规则定义是否存在
                    boolean isRuleDefExists = constraintRuleDefVOS.stream().anyMatch(itemRule ->
                                                                                             itemRule.getOid().equals(itemInfo.getRuleoid()));

                    if (isRuleDefExists) {
                        Optional<TyplmConstraintRuleDefVO> ruleDefOpt = constraintRuleDefVOS.stream()
                                .filter(itemRule -> itemRule.getOid().equals(itemInfo.getRuleoid()))
                                .findFirst();

                        if (ruleDefOpt.isPresent()) {
                            TyplmConstraintRuleDefVO itemDef = ruleDefOpt.get();

                            // 如果枚举OID是数字，则设置枚举定义OID
                            if (StringUtils.isNumeric(itemInfo.getEnumoid())) {
                                itemDef.setEnumerationDefOid(itemInfo.getEnumoid());
                            }

                            ruleList.add(itemDef);
                        }
                    }
                }

                // 处理最终的约束创建
                if (CollUtil.isNotEmpty(ruleList)) {
                    constraintCreateVO.setConstraintRuleDefVOS(ruleList);
                    TyplmLoggerUtil.debug(log, () -> "复制约束的constraintCreateVO为==>【{}】",
                                          () -> new Object[]{JSON.toJSONString(constraintCreateVO)});
                    this.typlmConstraintService.newConstraint(constraintCreateVO);
                }
            }
        }
    }


    private void copyChildClassInfo(ClassificationDO oldParentEntityInfo, ClassificationDO parentEntityInfo, Map<AttributeDefMapDO, AttributeDefMapDO> attrMap) {
        List<ClassificationDO> childList = this.queryClassificationByParentId(oldParentEntityInfo.getOid(), oldParentEntityInfo.getClassficationrootoid());
        if (CollUtil.isNotEmpty(childList)) {
            HashMap<IdentifierEntity, ClassificationDO> extendList = new HashMap<>();

            for (ClassificationDO itemInfo : childList) {
                ClassificationDO itemInfoTemp = new ClassificationDO();
                BeanUtil.copyProperties(itemInfo, itemInfoTemp);
                IdentifierEntity itemInfoEntity = new IdentifierEntity();
                itemInfoEntity.setOid(itemInfoTemp.getOid());
                itemInfoEntity.setOtype(itemInfoTemp.getOtype());
                itemInfo.setParentnodeoid(parentEntityInfo.getOid());
                itemInfo.setClassficationrootoid(parentEntityInfo.getClassficationrootoid());
                this.copyClassData(itemInfoEntity, itemInfo);
                TyplmCutOrCopyClassificationPostEvent copyClassificationPostEvent = new TyplmCutOrCopyClassificationPostEvent(
                        this, itemInfoEntity, itemInfo.getIdentifierRef(), false);
                TySpringBeanUtil.getApplicationContext().publishEvent(copyClassificationPostEvent);
                this.copyClassIba(itemInfoEntity, itemInfo, attrMap);
                this.copyChildClassInfo(itemInfoTemp, itemInfo, attrMap);
                extendList.put(itemInfoEntity, itemInfo);
            }

            extendList.forEach(this::copyClassExtend);
        }

    }

    private List<ClassificationDO> queryClassificationByParentId(BigInteger parentOid, BigInteger rootId) {
        if (Objects.isNull(parentOid) && Objects.isNull(rootId)) {
            return new ArrayList<>();
        } else {
            Example example = new Example(ClassificationDO.class, true, true);
            Example.Criteria criteria = example.createCriteria();
            if (Objects.nonNull(parentOid)) {
                criteria.andEqualTo("parentnodeoid", parentOid);
                TyplmLoggerUtil.debug(log, () -> "根据父oid查询分类的入参parentoid为==>【{}】", () -> new Object[]{parentOid});
            }

            if (Objects.nonNull(parentOid)) {
                criteria.andEqualTo("classficationrootoid", rootId);
                TyplmLoggerUtil.debug(log, () -> "根据rootid查询分类的入参rootid为==>【{}】", () -> new Object[]{rootId});
            }
            return this.typlmClassificationMapper.selectByExample(example);
        }
    }
}
